#!/usr/bin/env bash

if [ $EMBOX_GCC_ENV ] && [ -f $EMBOX_GCC_ENV ]; then
	. $EMBOX_GCC_ENV
else
	echo "No EMBOX_GCC_ENV is set" >&2
	exit 1
fi

cmd=$(basename $0)
case $cmd in
	*-ranlib)      C_CXX_FLAGS="";;
	*)             echo "Unknown flags for $cmd"; exit 1;;
esac

PWD_ARG_LINE="$(for i in $ARG_LINE; do echo ${i/$PWD/.}; done)"

if [[ "$cmd" == *clang ]]; then
	clang "$@" -target arm-none-eabi $PWD_ARG_LINE
	exit $?
else
	$EMBOX_CROSS_COMPILE${cmd#arch-embox-} "$@" $PWD_ARG_LINE
	exit $?
fi
